package com.monicash.monicash.information.modle

import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import com.monicash.monicash.app.LogUtils
import com.monicash.monicash.base.BaseModle
import com.monicash.monicash.netconfig.Apis
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.ResponseBody


class KycModle : BaseModle() {

    private val coroutineScope = CoroutineScope(Dispatchers.Default)

    companion object {
        val instant by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
            KycModle()
        }
    }


    fun getZiLiPageUserInfoConfig(map: MutableMap<String,String>): String {
        var result: String = ""
        coroutineScope.launch {
            try {
                val mapString = getZiLiPageJson(map, false)
                val request: RequestBody =
                    mapString.toRequestBody("text/plain".toMediaTypeOrNull())
                val data = Apis.apiKycServer.getZiLiPageUserInfoConfig(request)
                val responseBody: ResponseBody? = data.body()
                result = decryptingZiLiPageData(data)
                LogUtils.logE("e ：$result")
            } catch (e: Exception) {
                LogUtils.logE("e ：$e")
            }
        }
        return result
    }

    fun getZiLiPageUserFullInfo(map: MutableMap<String,String>): String {
        var result: String = ""
        coroutineScope.launch {
            try {
                val mapString = getZiLiPageJson(map, false)
                val request: RequestBody =
                    mapString.toRequestBody("text/plain".toMediaTypeOrNull())
                val data = Apis.apiKycServer.getZiLiPageUserFullInfo(request)
                val responseBody: ResponseBody? = data.body()
                result = decryptingZiLiPageData(data)
                LogUtils.logE("e ：$result")
            } catch (e: Exception) {
                LogUtils.logE("e ：$e")
            }
        }
        return result
    }

    fun updateZiLiPageUserInfo(map: MutableMap<String,String>): String {
        var result: String = ""
        coroutineScope.launch {
            try {
                val mapString = getZiLiPageJson(map, false)
                val request: RequestBody =
                    mapString.toRequestBody("text/plain".toMediaTypeOrNull())
                val data = Apis.apiKycServer.updateZiLiPageUserInfo(request)
                val responseBody: ResponseBody? = data.body()
                result = decryptingZiLiPageData(data)
                LogUtils.logE("e ：$result")
            } catch (e: Exception) {
                LogUtils.logE("e ：$e")
            }
        }
        return result
    }
}